home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / SourceCode / Inspectors / YourWS_Inspector / Text_Console.m < prev    next >
Text File  |  1995-06-12  |  1KB  |  42 lines

  1. /*
  2. ---------Text_Console.h------------
  3.  
  4. Adds a printf method to all Text instances within an application.
  5.  
  6. Thanks to Sam Streeper for posting the original version of this stuff to
  7. the world. 
  8.  
  9. You may freely copy, distribute, and reuse the code in this example.
  10. NeXT disclaims any warranty of any kind, expressed or  implied, as to its
  11. fitness for any particular use.
  12. ------------------------------------
  13. */
  14.  
  15. #import "Text_Console.h"
  16. #import <stdarg.h>
  17.  
  18. @implementation Text(Text_Console)
  19. #define BUFFERSIZE 512
  20.  
  21. - (int) printf:(const char *) format, ...
  22. {
  23.   int result, length = [self textLength];
  24.   char buffer[BUFFERSIZE];
  25.   va_list    ap;
  26.   
  27.   va_start(ap, format);
  28.   result = vsprintf(buffer, format, ap);
  29.   va_end(ap);
  30.  
  31.   // this is how one puts text into a Text object and goes to that selection.
  32.  
  33.   // put the cursor in the very last location and push the buffer in
  34.   [[self setSel:length :length] replaceSel:buffer];
  35.  
  36.   // scroll so that it is visible and redisplay
  37.   [[self scrollSelToVisible] display];
  38.   
  39.   return result;
  40. }
  41. @end
  42.